package com.example.myapplication.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.R;
import com.example.myapplication.view.ViewPagerIndicator;

import java.util.ArrayList;
import java.util.List;

public class Tab1Fragment extends Fragment {

    private ViewPagerIndicator indicator;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState){

        View view = inflater.inflate(R.layout.fragment,container,false);
        ViewPager imgP = view.findViewById(R.id.img_ip);

        indicator = view.findViewById(R.id.indicator);

        List<View> viewList = new ArrayList<>();

        ImageView img = new ImageView(getContext());
        img.setBackgroundResource(R.drawable.banner_1);
        viewList.add(img);
        ImageView img2 = new ImageView(getContext());
        img2.setBackgroundResource(R.drawable.banner_2);
        viewList.add(img2);
        ImageView img3 = new ImageView(getContext());
        img3.setBackgroundResource(R.drawable.banner_3);
        viewList.add(img3);

        indicator.setCount(viewList.size());
        indicator.setCurrent(0);

        ImgAdapter imgAdapter = new ImgAdapter(  viewList  );
        imgP.setAdapter(imgAdapter);

        imgP.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

            @Override
            public void onPageSelected(int position) {
                indicator.setCurrent(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {}
        });
        return view;
    }
}
